﻿<%@ Application Language="C#" %>
<%@ Import Namespace="SIMS.Company" %>
<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
       

       
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        CompanyProfileList _profileList = new CompanyProfileList();

        if (HttpRuntime.Cache[Global.CompanyListCacheId] != null)
        {
            _profileList = (CompanyProfileList)HttpRuntime.Cache[Global.CompanyListCacheId];
        }
        else
        {
            CompanyProfileDB _profileDB = new CompanyProfileDB();
            _profileList = _profileDB.GetProfileList();
            if (_profileList != null && _profileList.Count > 0)
            {
                HttpRuntime.Cache[Global.CompanyListCacheId] = _profileList;
            }
        }
        
        // Code that runs when a new session is started
        if (HttpContext.Current.Session[Global.CompanyId] == null && (_profileList != null && _profileList.Count > 0))
        {
            HttpContext.Current.Session[Global.CompanyId] = _profileList[0].Id.ToString();
            HttpContext.Current.Session[Global.CompanyName] = _profileList[0].CompanyName.ToString();
        }

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
